package com.seek.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seek.eduservice.entity.EduTeacher;
import com.seek.eduservice.mapper.EduTeacherMapper;
import com.seek.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author wml
 * @since 2022-01-09
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    // 分页查询讲师，返回 map 集合
    @Override
    public Map<String, Object> selectPage(Page<EduTeacher> page) {
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("sort");
        Page<EduTeacher> eduTeacherPage = baseMapper.selectPage(page, queryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("items", eduTeacherPage.getRecords());
        map.put("current", eduTeacherPage.getCurrent());
        map.put("pages", eduTeacherPage.getPages());
        map.put("size", eduTeacherPage.getSize());
        map.put("total", eduTeacherPage.getTotal());
        map.put("hasNext", eduTeacherPage.hasNext());
        map.put("hasPrevious", eduTeacherPage.hasPrevious());
        return map;
    }
}
